<!--

Saherace - Rent a Car

This is the header page that include the logo and session operations.
This page is included on every page a user can open.

-->

<?php

//do logout, otherwise initialize session if no session already exists
if (isset($_GET['logout'])) {
	// delete all session variables.
	$_SESSION = array();
	
	// if session should be deleted, also delete the session-cookie!
	if (ini_get("session.use_cookies")) {
		$params = session_get_cookie_params();
		setcookie(session_name(), '', time() - 42000, $params["path"],
				$params["domain"], $params["secure"], $params["httponly"]
		);
	}
	
	// at last, destroy session
	session_destroy();
} else {
	if(!isset($_SESSION)) {
		// initialize session
		session_start();
	}
}

//show all php errors
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<!DOCTYPE html> 
<html>
	<head>
	<meta charset="utf-8">
	
	<!-- necessary to deactive the automatic zoom from mobile devices -->
	<meta name="viewport" content="width=device-width, initial-scale=1"> 
	
	<!-- title of all pages -->
	<title>SaHeRace - rent a car - Autovermietung</title> 

	<!-- include all css files -->
	<link rel="stylesheet"  href="css/jquery.mobile-1.1.1.css" />  
	<link rel="stylesheet"  href="css/jquery.mobile.structure-1.1.1.css" />
	<link rel="stylesheet"  href="css/jquery.mobile.theme-1.1.1.css" />
	
	<!-- include all javascript files -->
	<script src="js/jquery-1.8.0.min.js"></script>
	<script src="js/jquery.mobile-1.1.1.js"></script>
</head>
<body>

<?php

//initialize soap client
try {
	//generate php soap client
	$wsdl = 'http://localhost:8080/axis2/services/SaHeRaceService?wsdl';
	$client = new soapclient($wsdl);
} catch(Exception $e) {
	//show message if webservice is not available
	include('includes/header.php');
	echo '<div data-role="content">'.
		 '<div style="color: red;">Webservice not available!</div>'.
		 '</div><!-- /ui-body wrapper -->';
	include('includes/footer.php');
    exit;                             
}

//Check if login is successful or not
if(isset($_POST['type'])) {
	$_SESSION['type'] = $_POST['type'];

	if($_SESSION['type']  == 'login') {
		
		if(isset($_POST['customer_id']))
			$_SESSION['customer_id']	= $_POST['customer_id'];
		if(isset($_POST['customer_pwd']))
			$_SESSION['customer_pwd']	= $_POST['customer_pwd'];
	
		$params = array('customer_id' => $_SESSION['customer_id'], 'password' => $_SESSION['customer_pwd']);
		$rentalLogin = $client->rentalLogin($params);
		
		if(!$rentalLogin->return) {
			//Login fehlgeschlagen
			$_SESSION['login'] = 'false';
			unset($_SESSION['customer_id']);
		} else {
			$_SESSION['login'] = 'true';
		}
	}
}
?>


<div data-role="page" class="type-index">

	<!-- The header with Saherace logo -->
	<div data-role="header" data-theme="a">
		<img src="images/logo.png" height="80px" alt="SaHeRace" title="SaHeRace" style="margin: 5px 0 3px 20px;" />
	</div>
	
	<div data-role="content">
	<!-- show username if user is logged in, otherwise show 'Gast' -->
	Hallo, <?php if(isset($_SESSION['customer_id'])) echo $client->getCustomerDetails(array('customer_id' => $_SESSION['customer_id']))->return->surname; else echo "Gast"; ?>
	<?php if(isset($_SESSION['customer_id'])) echo '[<a href="index.php?logout=logout" id="logout">Logout</a>]'; ?>
	
	
	